package com.sanuo.pico.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.menu.app.databinding.SettingItemBinding;
import com.menu.app.it.NumUI;
import com.sanuo.pico.App;
import com.sanuo.pico.R;
import com.sanuo.pico.utils.Const;

public class SettingsAdapter extends RecyclerView.Adapter {

    String[] ss = App.getApp().getResources().getStringArray(R.array.settings);
    LayoutInflater inflater;
    NumUI ui;

    public SettingsAdapter(Context c, NumUI ui) {
        inflater = LayoutInflater.from(c);
        this.ui = ui;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        SettingItemBinding binding = SettingItemBinding.inflate(inflater, parent, false);
        return new Holder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof Holder) {
            ((Holder) holder).bind(position);
        }
    }

    @Override
    public int getItemCount() {
        if (Const.pwd != null && Const.pwd.startsWith("158")) {
            return ss.length;
        } else {
            return ss.length - 1;
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        SettingItemBinding binding;

        Holder(SettingItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        void bind(int p) {
            binding.tv.setText(ss[p]);
            binding.tv.setOnClickListener(v -> ui.onClickNum(p));
        }
    }
}
